1
|
|
|
var Slf4j = require('@ama-team/voxengine-sdk').Logger.Slf4j |
2
|
|
|
var Validator = require('../Schema').Validator |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* @param {LoggerOptions} [options] |
6
|
|
|
* @class |
7
|
|
|
*/ |
8
|
|
|
function Printer (options) { |
9
|
|
|
var logger = Slf4j.factory(options, 'ama-team.vsf.api.printer') |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @param {TScenario} scenario |
13
|
|
|
*/ |
14
|
|
|
this.scenario = function (scenario) { |
15
|
|
|
logger.info('Scenario information:') |
16
|
|
|
logger.info('ID: {}', scenario.id || null) |
17
|
|
|
logger.info('Version: {}', scenario.version || null) |
18
|
|
|
logger.info('Environment: {}', scenario.environment || null) |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param {ViolationSet} violations |
23
|
|
|
*/ |
24
|
|
|
this.violations = function (violations) { |
25
|
|
|
var groups = violations.violations |
26
|
|
|
if (!Object.keys(groups).length) { |
27
|
|
|
logger.info('No violations have been found') |
28
|
|
|
return |
29
|
|
|
} |
30
|
|
|
logger.info('Found validation violations:') |
31
|
|
|
Object.keys(groups).forEach(function (path) { |
32
|
|
|
groups[path].forEach(function (v) { |
33
|
|
|
var severe = v.severity.weight > Validator.Severity.Minor |
34
|
|
|
var method = severe ? 'warn' : 'info' |
35
|
|
|
logger[method]('{}: {} ({})', path, v.message, v.severity.id) |
36
|
|
|
}) |
37
|
|
|
}) |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param {TRunResult} result |
42
|
|
|
*/ |
43
|
|
|
this.result = function (result) { |
44
|
|
|
var method = result.status.successful ? 'notice' : 'error' |
45
|
|
|
logger[method]('Framework run has finished in {} ms with status {}', |
46
|
|
|
result.duration, result.status.id) |
47
|
|
|
if (result.value) { |
48
|
|
|
logger.info('Result value:', result.value) |
49
|
|
|
} |
50
|
|
|
var stages = result.stages |
51
|
|
|
Object.keys(stages).forEach(function (name) { |
52
|
|
|
var result = stages[name] |
53
|
|
|
if (!result) { |
54
|
|
|
logger.info('{} stage hasn\'t been run', name) |
55
|
|
|
return |
56
|
|
|
} |
57
|
|
|
if (result.status.successful) { |
58
|
|
|
logger.info('{} stage has successfully finished in {} ms:', name, |
59
|
|
|
result.duration, result.value) |
60
|
|
|
} else { |
61
|
|
|
logger.error('{} stage has failed in {} ms:', name, result.duration, |
62
|
|
|
result.value || result.error) |
63
|
|
|
} |
64
|
|
|
}) |
65
|
|
|
if (stages.scenario) { |
66
|
|
|
logger.debug('Recapping scenario state history (limited to 100 entries):') |
67
|
|
|
stages.scenario.history.forEach(function (e) { |
68
|
|
|
logger.debug('{} -> {}: {} (hints: {}, value: {})', e.origin, e.target, |
69
|
|
|
e.status.id, e.hints, e.value) |
70
|
|
|
}) |
71
|
|
|
} |
72
|
|
|
return result |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
module.exports = { |
77
|
|
|
Printer: Printer |
78
|
|
|
} |
79
|
|
|
|